﻿using System;

namespace LogNaga.Logs
{
	/// <summary>
	/// 需要格式化记录<see cref="Exception"/>的log
	/// </summary>
	/// <remarks>需要将Exception记录到cache、DB等时可以从该基类继承</remarks>
	public abstract class FormattedLog : Log
	{
		/// <summary>
		/// 不允许实例化该类
		/// </summary>
		protected FormattedLog(){}

		#region override Log.Write

		/// <summary>
		/// 重写Log.Write方法
		/// </summary>
		/// <param name="errorEntry"><see cref="Error"/>实例</param>
		public sealed override void Write(Error errorEntry)
		{
			if(errorEntry == null)
			{
				throw new ArgumentNullException("errorEntry");
			}
			if(errorEntry.Exception == null)
			{
				throw new ArgumentNullException("errorEntry");
			}

			WriteToDestination(errorEntry);
		}

		#endregion

		/// <summary>
		/// 记录到数据源的具体实现
		/// </summary>
		/// <param name="errorEntry"><see cref="Error"/>实例</param>
		public abstract void WriteToDestination(Error errorEntry);
	}
}
